package com.hsnn.medstgmini.pro.base.controller;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.hsnn.medstgmini.Constants;
import com.hsnn.medstgmini.base.dict.model.form.DicAreaForm;
import com.hsnn.medstgmini.base.dict.service.DicAreaManager;
import com.hsnn.medstgmini.base.std.model.StdCompinfo;
import com.hsnn.medstgmini.base.std.model.form.StdCompInfoForm;
import com.hsnn.medstgmini.base.std.service.StdCompinfoManager;
import com.hsnn.medstgmini.base.std.service.StdHospInfoManager;
import com.hsnn.medstgmini.pro.base.model.BaseDelrelation;
import com.hsnn.medstgmini.pro.base.model.BaseDelrelationLog;
import com.hsnn.medstgmini.pro.base.model.BaseGoods;
import com.hsnn.medstgmini.pro.base.model.form.BaseDelrelationForm;
import com.hsnn.medstgmini.pro.base.service.BaseDelrelationByCentreManager;
import com.hsnn.medstgmini.pro.base.service.BaseDelrelationManager;
import com.hsnn.medstgmini.pro.base.service.BaseGoodsManager;
import com.hsnn.medstgmini.sys.model.SysUser;
import com.hsnn.medstgmini.util.Pagination;
/**
 * 
 *@category 配送关系管理
 *@author 邱磊
 *@date 2015年6月18日 上午9:55:57
 */
@Controller
@RequestMapping("/baseDel")
public class BaseDelrelationController {
	private static final Logger log = Logger.getLogger(BaseDelrelationController.class);
	@Autowired
	private BaseDelrelationManager baseDelrelationManager;
	@Autowired
	private BaseDelrelationByCentreManager baseDelrelationByCentreManager;
	@Autowired
	private  HttpServletRequest request;
	@Autowired
	private BaseGoodsManager baseGoodsManager;
	@Autowired
	private HttpSession session;
	@Value("#{sysProp['system.province']}")
    private String sysProvince;
	@Value("#{sysProp['system.delWithHosp']}")
    private boolean delWithHosp;
	@Autowired
	private StdHospInfoManager hospManager;
	@Value("#{sysProp['system.linxuan']}")
	private boolean linxuan;
	@Autowired
	private StdCompinfoManager compManager;
	@Value("#{sysProp['system.gzfjydel']}")
	private String gzfjydel;
	/**
	 * 
	 *@category 配送企业确认配送关系与拒绝配送关系
	 *@author 邱磊
	 *@date 2015年6月18日 下午3:41:02
	 *@return
	 */
	@RequestMapping("/confirmDel")
	@ResponseBody
	public Pagination confirmDel(){
		Pagination page = new Pagination(request);
		page.getConditions().put("status", request.getParameter("status"));
		page.getConditions().put("delRelId", request.getParameter("delRelId"));
		try {
			baseDelrelationManager.confirmDel(page);
			page.setSuccess(true);
		} catch (Exception e) {
			// TODO: handle exception
			page.setSuccess(false);
		}
		return page;
	}
	/**
	 * @category 获取当前登陆人信息
	 * @date 2015年6月14日
	 * @return
	 */
	private SysUser getUser() {
		return (SysUser) session.getAttribute(Constants.USERINFO);
	}
	/**
	 * 
	 * @category 解除配送关系 
	 * @param 
	 * @return
	 */
	@RequestMapping("/changeStatus")
	@ResponseBody
	public Pagination changeStatus(BaseDelrelation baseDelrelation) {
		Pagination page = new Pagination(request);
		try {
			if (baseDelrelation != null && baseDelrelation.getDelRelId() != null) {
				//baseDelrelation.setUpdUser(getUser().getId());
				baseDelrelation.setUpdUser(getUser().getUsername());
				baseDelrelationManager.changeStatus(baseDelrelation);
				page.setSuccess(true);
			}
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	@Autowired
	private DicAreaManager dicAreaManager;
	@Value("#{sysProp['system.province']}")
    private String province;
	/**
	 * 
	 *@category 查看配送关系（配送企业）
	 *@author 张俊
	 *@date 2015年6月19日
	 *@return
	 */
	@RequestMapping("/toBaseDelRelationList" )
	public String toBaseDelrelationList(){
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
		if("1".equals(gzfjydel)) {
			return "/pro/base/baseDelRelationFjyList";
		}
		return "/pro/base/baseDelRelationList";
	}
	/**
	 * 
	 *@category 跳转查看配送确认（配送企业）
	 *@author wangbing
	 *@date 2015年6月19日
	 *@return
	 */
	@RequestMapping("/toBaseDelRelationToConfirmList" )
	public String toBaseDelRelationToConfirmList(){
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		request.setAttribute("status", Constants.DEL_STATUS_REFUSED);
		return "/pro/base/baseDelRelationToConfirmList";
	}
	/**
	 * 
	 *@category 查询当前配送企业的所有药品生产关系
	 *@author 张俊
	 *@date 2015年6月19日
	 *@return
	 */
	@RequestMapping("/getBaseDelRelationList" )
	@ResponseBody
	public Pagination getBaseDelRelationList(){
		log.info("查询当前配送企业的所有药品生产关系");
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("status", request.getParameter("status"));
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page = baseDelrelationManager.getBaseDelRelationList(page);
		return page;
	}
	/**
	 * 
	 * @category 跳向配送关系日志查看空页面
	 * @author 张俊
	 * @date 2015年6月24日21:14:08
	 * @param 
	 * @return
	 */
	@RequestMapping("/toBaseDelRelationLogList")
	public String toBaseDelRelationLogList() {
		request.setAttribute("delRelId", request.getParameter("delRelId"));
		return "/pro/base/baseDelRelationLogByPs";
	}
	
	@RequestMapping("/toBaseDelRelationLogByPs")
	public String toBaseDelRelationLogByPs() {
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/baseDelRelationLogByPs";
	}
	@RequestMapping("/getBaseDelRelationLogByPs")
	@ResponseBody
	public Pagination getBaseDelRelationLogByPs() {
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("startTime", request.getParameter("startTime"));
		page.getConditions().put("endTime", request.getParameter("endTime"));
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compId = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("delCompId", compId);
		page = baseDelrelationManager.getBaseDelRelationLogByPs(page);
		return page;
	}
	/**
	 * 
	 * @category 配送关系日志列表
	 * @author 张俊
	 * @date 2015-06-24 21:16:46
	 * @param 
	 * @return
	 */
	@RequestMapping("/getBaseDelRelationLogList")
	@ResponseBody
	public Pagination getBaseDelRelationLogList(BaseDelrelationLog baseDelrelationLog) {
		Pagination page = new Pagination(request);
		try {
			List<BaseDelrelationLog> list = baseDelrelationManager.getBaseDelRelationLogList(page, baseDelrelationLog);
			page.setRows(list);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	
	/**
	 * 
	 *@category 中心端配送关系管理明细 页面跳转
	 *@author 言科
	 *@date 2015年6月26日
	 *String
	 */
	@RequestMapping("/toBaseDelByCentreListSee" )
	public String toBaseDelByCentreListSee(){
		return "/pro/base/baseDelByCentreListSee";
	}
	
	@RequestMapping("/getBaseDelByCentreListSee" )
	@ResponseBody
	public Pagination getBaseDelByCentreListSee(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("drugSource", request.getParameter("drugSource"));
		page = baseDelrelationByCentreManager.getBaseDelByCentreListSee(page);
		return page;
		
	}

	
	/**
	 * 
	 *@category  中心端配送关系管理 设置配送关系列表
	 *@author 言科
	 *@date 2015年6月26日
	 *Pagination
	 */
	@RequestMapping("/toBaseDelByCentreListManage" )
	public String toBaseDelByCentreListManage(){
		return "/pro/base/baseDelByCentreListManage";
	}
	
	
	@RequestMapping("/getBaseDelByCentreListManage" )
	@ResponseBody
	public Pagination getBaseDelByCentreListManage(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page = baseDelrelationByCentreManager.getBaseDelByCentreListManage(page);
		return page;
	}
	
	/**
	 * 
	 *@category  中心端 查询所有药品和配送企业关系 已配送关系明细
	 *@author 言科
	 *@date 2015年6月26日
	 *void
	 */
	@RequestMapping("/toBaseDelCentreByCompList" )
	public String toBaseDelCentreByCompList(){
		if (delWithHosp){
			request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
			request.setAttribute("sysProvince", sysProvince);
			Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
			request.setAttribute("sysProvinceName", area.get("area_name"));
			return "/pro/base/baseDelCentreWithHospList";
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
		return "/pro/base/baseDelCentreByCompList";
	}
	
	@RequestMapping("/getBaseDelCentreByCompList" )
	@ResponseBody
	public Pagination getBaseDelCentreByCompList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("projId", request.getParameter("projId"));
		page.getConditions().put("projectName", request.getParameter("projectName"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("delCompName", request.getParameter("delCompName"));
		page = baseGoodsManager.getBaseDelCentreByCompList(page);
		return page;
	}
	
	
	
	/**
	 * 
	 *@category  中心端配送关系管理 设置配送关系列表  根据区域设置配送企业
	 *@author 言科
	 *@date 2015年6月26日
	 *Pagination
	 */
	@RequestMapping("/setDelByArea")
	@ResponseBody
	public String setDelByArea(String array){
		if (array != null && !"".equals(array)) {
			Gson gson = new Gson();
			Type type = new TypeToken<List<StdCompInfoForm>>(){}.getType();
			List<StdCompInfoForm> list = gson.fromJson(array, type);
			if (list != null && !list.isEmpty()) {
				for(StdCompInfoForm dp:list){
					dp.setUpdDatetime(array);
				}
				return baseDelrelationByCentreManager.setDelByArea(list);
			}
		}
		
		return "failed";
		
	}
	
	
	/**
	 * 
	 *@category 中心端配送关系管理 状态转换
	 *@author 言科
	 *@date 2015年6月23日
	 *String
	 */
	@RequestMapping("/switchStatus")
	@ResponseBody
	public Pagination switchStatus(String goodsCode,Short status){
		Pagination page = new Pagination(request);
		try {
			baseDelrelationByCentreManager.switchStatus(goodsCode, status);
			page.setSuccess(true);
		} catch (Exception e) {
			page.setSuccess(false);
			
		}
		return page;
		
	}
	@RequestMapping("/toDrugByPS")
	public String toDrugByPSList() {
		return "/pro/base/baseDrugByPS";
	}
	
	/**
	 * @category 我配送的商品数据获取【配送企业】
	 * @author 韩守松
	 * @date   2015年12月9日
	 * @param  @return
	 */
	@RequestMapping("/getDrugByPS")
	@ResponseBody
	public Pagination getDrugByPSList() {
		log.info("我配送的商品数据获取【配送企业】");
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compId = ((StdCompinfo )user.getInfo()).getCompCode();
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
			page.getConditions().put("drugCode", request.getParameter("drugCode"));
			page.getConditions().put("drugName", request.getParameter("drugName"));
			page.getConditions().put("compName", request.getParameter("compName"));
			page.getConditions().put("compId", compId);
			page = baseDelrelationManager.getDrugByPS(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * 
	 *@category 中心端配送关系管理 配送关系日志
	 *@author 言科
	 *@date 2015年6月23日
	 *String
	 */
	@RequestMapping("/toBaseDelrelationByCentreListLog")
	public String toBaseDelrelationByCentreListLog() {
		request.setAttribute("delRelId", request.getParameter("delRelId"));
		return "/pro/base/baseDelByCentreListLog";
	}
	
	@SuppressWarnings("unused")
	@RequestMapping("/getBaseDelrelationByCentreListLog")
	@ResponseBody
	public Pagination getBaseDelrelationByCentreListLog(BaseDelrelationLog baseDelrelationLog) {
		Pagination page = new Pagination(request);
		try {
			List<BaseDelrelationLog> list = baseDelrelationByCentreManager.getBaseDelrelationByCentreListLog(page, baseDelrelationLog);
			page.setSuccess(true);
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
		}
		return page;
	}
	
	/** 获取配送区域信息【配送企业】
	 * @category 
	 * @author 韩守松
	 * @date   2015年12月9日
	 * @param  @return
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping("/toDrugByPSArea")
	public String toDrugByPSAreaList() {
		log.info("获取配送区域信息【配送企业】");
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Pagination page = new Pagination(request);
		BaseGoods form = new BaseGoods();
		form.setGoodsCode(request.getParameter("goodsCode"));
		page.setForm(form);
		page = baseGoodsManager.getDataList(page);
		List<BaseGoods> list = (List<BaseGoods>) page.getRows();
		if (null != list && list.size() > 0){
			request.setAttribute("form", list.get(0));
		}
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
		return "/pro/base/baseDrugByPSArea";
	}
	@RequestMapping("/getDrugByPSArea")
	@ResponseBody
	public Pagination getDrugByPSAreaList() {
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compId = ((StdCompinfo )user.getInfo()).getCompCode();
		Pagination page = new Pagination(request);
		try {
			page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
			page.getConditions().put("areaCode", request.getParameter("areaCode"));
			page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
			page.getConditions().put("compId", compId);
			page = baseDelrelationManager.getDrugByPSArea(page);
			page.setSuccess(true);
		} catch (Exception e) {
			log.error("",e);
			page.setSuccess(false);
		}
		return page;
	}
	
	/**
	 * 
	 *@category  中心端配送关系根据商品码查询商品价格明细
	 *@author 言科
	 *@date 2015年6月20日
	 *Pagination
	 */
	@RequestMapping("/toBaseDelByCentreGoods" )
	public String toBaseDelByCentreGoods(){
//		request.setAttribute("delRelId", request.getParameter("delRelId"));
//		request.setAttribute("drugCode", request.getParameter("drugCode"));
		return "/pro/base/baseDelByCentreGoods";
	}
	
	@RequestMapping("/getBaseDelByCentreGoods" )
	@ResponseBody
	public Pagination getBaseDelByCentreGoods(){
		Pagination page = new Pagination(request);
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("formName", request.getParameter("formName"));
		page.getConditions().put("specName", request.getParameter("specName"));
		page.getConditions().put("factor", request.getParameter("factor"));
		page.getConditions().put("unit", request.getParameter("unit"));
		page.getConditions().put("proPriceLimit", request.getParameter("proPriceLimit"));
		page.getConditions().put("retailPriceLimit", request.getParameter("retailPriceLimit"));
		
		page = baseDelrelationByCentreManager.getBaseDelByCentreGoods(page);
		return page;
	}
	
	
	/**
	 * 
	 *@category 跳向中心设置商品配送关系列表页面
	 *@author 邱磊
	 *@date 2015年6月17日 上午10:58:57
	 *@return
	 */
	@RequestMapping("/toDelDrugList")
	public String toProDelDrugList(){
		if (delWithHosp){
			return "/pro/base/delProdCompList"; 
		}
		return "/pro/base/baseGoodsDelByCenterList";
	}
	/**
	 * 
	 *@category 获取中心设置商品配送关系列表
	 *@author 邱磊
	 *@date 2015年6月17日 上午11:04:22
	 *@return
	 */
	@RequestMapping("/getDelDrugDataList")
	@ResponseBody
	public Pagination getDelDrugDataList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("projId", request.getParameter("projId"));
		page.getConditions().put("projName", request.getParameter("projName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page = baseDelrelationManager.getDelDrugDataList(page);
		return page;
		
	}
	
	/**
	 * 
	 *@category 跳向根据区域设置配送企业页面
	 *@author 邱磊
	 *@date 2015年6月17日 下午4:21:40
	 *@return
	 */
	@RequestMapping("/toCenterDelByArea")
	public String toCenterDelByArea() {
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		DicAreaForm area = dicAreaManager.getAreaById(province);
		request.setAttribute("area", area);
		request.setAttribute("form", form);
		return "/pro/base/centerDelByArea";
	}
	/**
	 * 
	 *@category 跳向按区域设置配送关系（选择配送企业）
	 *@author 邱磊
	 *@date 2015年6月30日 下午5:09:17
	 *@return
	 */
	@RequestMapping("/toDelCompSelect" )
	public String toDelCompSelect(String areaId, String areaName){
		try {
			areaName = new String(areaName.getBytes("ISO8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		request.setAttribute("areaName", areaName);
		if(linxuan){
			request.setAttribute("type", 1);
		}else{
			request.setAttribute("type", 0);
		}
		return "/pro/base/centerDelSelComp";
	}
	/**
	 * 
	 *@category 跳向按企业设置配送区域
	 *@author 邱磊
	 *@date 2015年7月2日 上午11:02:57
	 *@return
	 */
	@RequestMapping("/toSetDelByComp" )
	public String toSetDelByComp(){
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		return "/pro/base/centerDelByComp";
	}
	@RequestMapping("/toSetDelArea" )
	public String toSetDelArea(){
		try {
			request.setAttribute("compName", URLDecoder.decode(request.getParameter("compName"), "utf-8"));
		} catch (Exception e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/centerAreaSetDel";
	}
	/**
	 * 
	 *@category 查看商品在某区域设置的配送关系日志
	 *@author 邱磊
	 *@date 2015年7月2日 上午9:16:58
	 *@return
	 */
	@RequestMapping("/toDelLogByAreaList" )
	public String toDelLogByAreaList(){
		try {
			String areaName = request.getParameter("areaName");
			areaName = new String(areaName.getBytes("ISO8859-1"),"utf-8");
			request.setAttribute("areaName", areaName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		return "/pro/base/centerDelLogByAreaList";
	}
	@RequestMapping("/toDelLogByCompList" )
	public String toDelLogByCompList(){
		try {
			String compName = request.getParameter("compName");
			compName = new String(compName.getBytes("ISO8859-1"),"utf-8");
			request.setAttribute("compName", compName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		return "/pro/base/centerAreaSetDelLog";
	}
	/**
	 * 
	 *@category 跳向按配送企业设置配送区域的配送区域列表页面
	 *@author 邱磊
	 *@date 2015年7月2日 下午1:58:51
	 *@return
	 */
	@RequestMapping("/toDelArea" )
	public String toDelArea(){
		try {
			String compName = request.getParameter("compName");
			compName = new String(compName.getBytes("ISO8859-1"),"utf-8");
			request.setAttribute("compName", compName);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		request.setAttribute("compCode", request.getParameter("compCode"));
		request.setAttribute("goodsCode", request.getParameter("goodsCode"));
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		DicAreaForm area = dicAreaManager.getDicAreaById(province);
		request.setAttribute("area", area);
		if(linxuan){
			request.setAttribute("linxuan", 1);
		}else{
			request.setAttribute("linxuan", 0);
		}
		return "/pro/base/centerDelArea";
	}
	/**
	 * 
	 */
	@RequestMapping("/removeDell" )
	@ResponseBody
	public Pagination removeDell(String array){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<String>>() {
				}.getType();
				List<String> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
					baseDelrelationManager.removeDell(list,user.getId());
					page.setSuccess(true);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
	/**
	 * 
	 *@category 中心端跳向地区页
	 *@author 邱磊
	 *@date 2015年11月19日 下午7:32:31
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toSelectDelArea")
	public String toSelectDelArea(){
		List<Map<String, Object>> list = dicAreaManager.getAreaByFatherId(sysProvince);
		request.setAttribute("list", list);
		return "/pro/base/selectDelArea";
	}
	/**
	 * 
	 *@category 中心端跳向地区页
	 *@author 邱磊
	 *@date 2015年11月19日 下午7:32:31
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toSelectDelAreaResult")
	public String toSelectDelAreaResult(){
		List<Map<String, Object>> list = dicAreaManager.getAreaByFatherId(sysProvince);
		request.setAttribute("list", list);
		return "/pro/base/selectDelAreaResult";
	}
	/**
	 * 
	 *@category 获取地区List
	 *@author 邱磊
	 *@date 2015年11月20日 上午10:30:56
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getSelectDelArea")
	@ResponseBody
	public Pagination getSelectDelArea(){
		Pagination page = new Pagination();
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("areaName", request.getParameter("areaName"));
		page.getConditions().put("fatherId", request.getParameter("fatherId"));
		return dicAreaManager.getMyProvinceArea(page);
	}
	
	/**
	 * 
	 *@category 中心端跳向遴选页面
	 *@author 邱磊
	 *@date 2015年11月19日 下午7:32:31
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toSelectDel")
	public String toSelectDel(){
		String areaCode = request.getParameter("areaCode");
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(areaCode);
		request.setAttribute("areaName", area.get("area_name"));
		request.setAttribute("areaCode", request.getParameter("areaCode"));
		return "/pro/base/selectDel";
	}
	@RequestMapping("/toSelectDelResult")
	public String toSelectDelResult(){
		String areaCode = request.getParameter("areaCode");
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(areaCode);
		request.setAttribute("areaName", area.get("area_name"));
		request.setAttribute("areaCode", request.getParameter("areaCode"));
		return "/pro/base/selectDelResult";
	}
	
	
	/**
	 * 
	 *@category 获取未被遴选的配送企业
	 *@author 邱磊
	 *@date 2015年11月19日 下午8:28:38
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getSelectDelData")
	@ResponseBody
	public Pagination getSelectDelData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		return baseDelrelationManager.getSelectDelData(page);
	}
	@RequestMapping("/getSelectDelResultData")
	@ResponseBody
	public Pagination getSelectDelResultData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("status", "2");
		return baseDelrelationManager.getSelectDelResultData(page);
	}
	/**
	 * 
	 *@category 中心遴选配送企业
	 *@author 邱磊
	 *@date 2015年11月20日 上午10:10:32
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/confirmDelArea")
	@ResponseBody
	public Pagination confirmDelArea(String array) {
		Pagination page = new Pagination();
		if (StringUtils.isNotBlank(array)){
			Gson gson = new Gson();
			Type type = new TypeToken<List<BaseDelrelationForm>>() { }.getType();
			List<BaseDelrelationForm> list = gson.fromJson(array, type);
			try {
				page.getConditions().put("areaCode", request.getParameter("areaCode"));
				SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
				page.getConditions().put("userId", user.getId());
				page.setRows(list);
				page = baseDelrelationManager.confirmDelArea(page);
			} catch (Exception e) {
				log.error("确定配送地区遴选：", e);
				page.setSuccess(false);
				page.setMsg("遴选失败！");
			}
		} else {
			page.setSuccess(false);
			page.setMsg("请选择要要遴选的配送关系！");
		}
		return page;
	}
	
	/**
	 * 
	 *@category 跳向设置配送关系生产企业列表
	 *@author 邱磊
	 *@date 2015年11月23日 下午4:27:43
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toDelProdCompList")
	public String toDelProdCompList(){
		return "/pro/base/delProdCompList";
	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月23日 下午5:48:00
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getDelProdCompData")
	@ResponseBody
	public Pagination getDelProdCompData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		return baseDelrelationManager.getDelProdCompData(page);
	}
	/**
	 * 
	 *@category 路向设置配送关系医疗机构页面
	 *@author 邱磊
	 *@date 2015年11月23日 上午9:12:29
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toDelByHospList")
	public String toDelByHospList(){
		request.setAttribute("sysProvince", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("sysProvinceName", area.get("area_name"));
		Map<String, Object> comp = compManager.getCompinfoByCode(request.getParameter("compCode"));
		request.setAttribute("compName", comp.get("comp_name"));
		return "/pro/base/delByHospLis";
	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月23日 上午10:36:09
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getDelByHospData")
	@ResponseBody
	public Pagination getDelByHospData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("hospCode", request.getParameter("hospCode"));
		page.getConditions().put("hospName", request.getParameter("hospName"));
		page.getConditions().put("hospClassify", request.getParameter("hospClassify"));
		page.getConditions().put("hospLevel", request.getParameter("hospLevel"));
		page.getConditions().put("areaId", request.getParameter("areaId"));
		page.getConditions().put("fatherId", request.getParameter("fatherId"));
		page.getConditions().put("compCode", request.getParameter("compCode"));
		return baseDelrelationManager.getDelByHospData(page);
	}
	@RequestMapping("/toSetDelByHospWithDelcompList")
	public String toSetDelByHospWithDelcompList(){
		String hospCode = request.getParameter("hospCode");
		Map<String, Object> hosp = hospManager.getStdHospInfoByCode(hospCode);
		if (null != hosp && hosp.size() > 0){
			request.setAttribute("hospName", hosp.get("hosp_name"));
		}
		Map<String, Object> comp = compManager.getCompinfoByCode(request.getParameter("compCode"));
		request.setAttribute("compName", comp.get("comp_name"));
		return "/pro/base/setDelByHospWithDelcompList";
	}
	@RequestMapping("/getSetDelByHospWithDelcompData")
	@ResponseBody
	public Pagination getSetDelByHospWithDelcompData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("delCompCode", request.getParameter("delCompCode"));
		page.getConditions().put("delCompName", request.getParameter("delCompName"));
		Map<String, Object> hosp = hospManager.getStdHospInfoByCode(request.getParameter("hospCode"));
		page.getConditions().put("hospCode", request.getParameter("hospCode"));
		page.getConditions().put("hospClass", hosp.get("hosp_classify").toString());
		return baseDelrelationManager.getSetDelByHospWithDelcompData(page);
	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月23日 下午2:11:27
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/setDelByHospWithDelcomp")
	@ResponseBody
	public Pagination setDelByHospWithDelcomp(String array){
		Pagination page = new Pagination();
		if (StringUtils.isNotBlank(array)){
			Gson gson = new Gson();
			Type type = new TypeToken<List<BaseDelrelation>>() { }.getType();
			List<BaseDelrelation> list = gson.fromJson(array, type);
			try {
				page.getConditions().put("hospCode", request.getParameter("hospCode"));
				SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
				page.getConditions().put("userId", user.getId());
				page.getConditions().put("compCode", request.getParameter("compCode"));
				page.setRows(list);
				page = baseDelrelationManager.setDelByHospWithDelcomp(page);
			} catch (Exception e) {
				log.error("设置配送企业：", e);
				page.setSuccess(false);
				page.setMsg("设置置失败！");
			}
			return page;
		} else {
			page.setSuccess(false);
			page.setMsg("请选择要设置的配送企业！");
		}
		return page;
	}
	@RequestMapping("/toDelByHospLog")
	public String toDelByHospLog(){
		String hospCode = request.getParameter("hospCode");
		Map<String, Object> hosp = hospManager.getStdHospInfoByCode(hospCode);
		if (null != hosp && hosp.size() > 0){
			request.setAttribute("hospName", hosp.get("hosp_name"));
		}
		Map<String, Object> form = baseGoodsManager.getBaseGoodsByCode(request.getParameter("goodsCode"));
		request.setAttribute("form", form);
		return "/pro/base/delByHospLog";
	}
	@RequestMapping("/getDelByHospLogData")
	@ResponseBody
	public Pagination getDelByHospLogData(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compCode", request.getParameter("compCode"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("startDate", request.getParameter("startDate"));
		page.getConditions().put("endDate", request.getParameter("endDate"));
		page.getConditions().put("hospCode", request.getParameter("hospCode"));
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page = baseDelrelationManager.getDelByHospLogData(page);
		return page;
	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月24日 上午10:46:53
	 *@param 
	 *@return String
	 */
//	@RequestMapping("/toHaveDelHospByDelcomp")
//	public String toHaveDelHospByDelcomp(){
//		request.setAttribute("sysProvince", sysProvince);
//		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
//		request.setAttribute("sysProvinceName", area.get("area_name"));
//		Map<String, Object> comp = compManager.getCompinfoByCode(request.getParameter("compCode"));
//		request.setAttribute("compName", comp.get("comp_name"));
//		return "/pro/base/haveDelHospByDelcomp";
//	}
	
//	public Pagination getHaveDelHospByDelcomp(){
//		Pagination page = new Pagination(request);
//		page.getConditions().put("hospCode", request.getParameter("hospCode"));
//		page.getConditions().put("hospName", request.getParameter("hospName"));
//		page.getConditions().put("hospClassify", request.getParameter("hospClassify"));
//		page.getConditions().put("hospLevel", request.getParameter("hospLevel"));
//		page.getConditions().put("areaId", request.getParameter("areaId"));
//		page.getConditions().put("fatherId", request.getParameter("fatherId"));
//		page.getConditions().put("compCode", request.getParameter("compCode"));
//		return baseDelrelationManager.getHaveDelHospByDelcomp(page);
//	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月24日 上午11:35:50
	 *@param 
	 *@return String
	 */
	@RequestMapping("/toBaseDelCentreWithHospList")
	public String toBaseDelCentreWithHospList(){
		request.setAttribute("status", Constants.DEL_STATUS_REMOVE);
		request.setAttribute("sysProvince", sysProvince);
		Map<String, Object> area = dicAreaManager.getAreaByAreaId(sysProvince);
		request.setAttribute("sysProvinceName", area.get("area_name"));
		return "/pro/base/baseDelCentreWithHospList";
	}
	/**
	 * 
	 *@category 
	 *@author 邱磊
	 *@date 2015年11月24日 上午11:36:05
	 *@param 
	 *@return Pagination
	 */
	@RequestMapping("/getBaseDelCentreWithHospList")
	@ResponseBody
	public Pagination getBaseDelCentreWithHospList(){
		Pagination page = new Pagination(request);
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("delCompName", request.getParameter("delCompName"));
		page.getConditions().put("hospName", request.getParameter("hospName"));
		page = baseDelrelationManager.getBaseDelCentreWithHospList(page);
		return page;
	}
	
	/**
	 * @category 配送企业获取待确认配送的商品数据
	 * @author 韩守松
	 * @date   2015年12月8日
	 * @param  @return
	 */
	@RequestMapping("/getWaitDelOKGoods")
	@ResponseBody
	public Pagination getWaitDelOKGoods(){
		Pagination page = new Pagination(request);
		page.getConditions().put("goodsCode", request.getParameter("goodsCode"));
		page.getConditions().put("drugCode", request.getParameter("drugCode"));
		page.getConditions().put("drugName", request.getParameter("drugName"));
		page.getConditions().put("compName", request.getParameter("compName"));
		page.getConditions().put("areaCode", request.getParameter("areaCode"));
		page.getConditions().put("fatherCode", request.getParameter("fatherCode"));
		page.getConditions().put("status", request.getParameter("status"));
		SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
		String compCode = ((StdCompinfo )user.getInfo()).getCompCode();
		page.getConditions().put("compCode", compCode);
		page = baseDelrelationManager.getWaitDelOKGoods(page);
		return page;
	}
	
	/**
	 * @category 配送企业 确认配送关系
	 * @author 韩守松
	 * @date   2015年12月8日
	 * @param  @param array
	 * @param  @return
	 */
	@RequestMapping("/delOKDel" )
	@ResponseBody
	public Pagination delOKDel(String array){
		Pagination page = new Pagination(request);
		try {
			if (array != null && !"".equals(array)) {
				Gson gson = new Gson();
				Type type = new TypeToken<List<String>>() {
				}.getType();
				List<String> list = gson.fromJson(array, type);
				if (list != null && !list.isEmpty()) {
					SysUser user=(SysUser) request.getSession().getAttribute(Constants.USERINFO);
					baseDelrelationManager.removeDell(list,user.getId());
					page.setSuccess(true);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
			page.setSuccess(false);
			page.setMsg("操作失败！");
		}
		return page;
	}
}
